package implementation.sort;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;
import implementation.sort.AbstractSorter;

import java.util.Comparator;
import java.util.List;


public class BubbleSort extends AbstractSorter {

    public BubbleSort() {
        super(SorterType.BUBBLE);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        int i = 0;
        boolean b = true;
        while(i< ts.size()-1 && b){
            b = false;
            for (int j = 0; j < ts.size() - i - 1; j++) {
                if (greater(tComparator, ts, j, j + 1)) {
                    swap(ts, j, j + 1);
                    b = true;
                }
            }
            i++;
        }
    }
}


